<?php
require_once(dirname(__FILE__) . '/config/index.php');

$_SERVER["SERVER_NAME"] = 'haddock';
define('PRETTY_URLS', true);

class TestOfLinks extends UnitTestCase {
	
	public function testUrl() {
		$this->assertEqual(Nina_Links::url('controller', 'action', 1, array('order' => 'asc'), 'top'), 'http://'.$_SERVER["SERVER_NAME"].'/controller/action/1?order=asc#top');
	}

	public function testHyperlink() {
		$this->assertEqual(Nina_Links::hyperlink('Hyperlink', 'controller', 'action', 1, array('order' => 'asc'), 'top', 'class', 'target', 'Alt'), '<a href="http://'.$_SERVER["SERVER_NAME"].'/controller/action/1?order=asc#top" class="class" title="Alt" target="target">Hyperlink</a>');
	}

	public function testImage() {
		$this->assertEqual(Nina_Links::image('images/image.jpg', 'image', 'My Image'), '<img src="images/image.jpg" class="image" alt="My Image"/>');
	}

	public function testButtonTo() {
		$this->assertEqual(Nina_Links::button_to('Button To', 'controller', 'action', 1, array('order' => 'asc'), 'top', 'class', 'Alt'), '<input type="button" value="Button To" onclick="javascript:window.location.href=\'http://'.$_SERVER["SERVER_NAME"].'/controller/action/1?order=asc#top\';" class="class" title="Alt"/>');
	}

	public function testButtonToFunction() {
		$this->assertEqual(Nina_Links::button_to_function('Button To Function', 'function()', 'class', 'Alt'), '<input type="button" value="Button To Function" onclick="javascript:function()" class="class" title="Alt"/>');
	}
	
	public function testForm() {
		$this->assertEqual(Nina_Links::form('action', 'method', 'name', 'class', 'encoding', 'target'), '<form action="action" method="method" name="name" id="name" enctype="encoding" class="class" target="target">' . PHP_EOL);
	}
	
	public function testSelectTag() {
		$this->assertEqual(Nina_Links::select_tag('id', array(array('option1', 1), array('option2', 2)), 2, true, 'class'), '<select id="id" name="id" class="class"><option value="">Select...</option><option value="1">option1</option><option value="2" selected="selected">option2</option></select>');
	
		$this->assertEqual(Nina_Links::select_tag('id', array(1 => 'option1', 2 => 'option2'), 2, true, 'class'), '<select id="id" name="id" class="class"><option value="">Select...</option><option value="1">option1</option><option value="2" selected="selected">option2</option></select>');
	}
	
	public function testSelectGroupTag() {
		$this->assertEqual(Nina_Links::select_group_tag('id', array('group1' => array(array('option1', 1), array('option2', 2))), 2, true, 'class'), '<select id="id" name="id" class="class"><option value="">Select...</option><optgroup label="group1"><option value="1">option1</option><option value="2" selected="selected">option2</option></optgroup></select>');
	
		$this->assertEqual(Nina_Links::select_group_tag('id', array('group1' => array(1 => 'option1', 2 => 'option2')), 2, true, 'class'), '<select id="id" name="id" class="class"><option value="">Select...</option><optgroup label="group1"><option value="1">option1</option><option value="2" selected="selected">option2</option></optgroup></select>');
	}
}